package other

import (
	"go-gin-api/app/model"
	"go-gin-api/app/model/github"
	"go-gin-api/app/util"

	"github.com/gin-gonic/gin"
)

// DeleteGithubByID 删除项目根据id
func DeleteGithubByID(c *gin.Context) *util.Response {
	result := github.Github{}
	if err := model.DB.Where("id=?", c.Query("id")).Find(&result).Error; err != nil {
		return &util.Response{
			Code:    40000,
			Message: "failed",
			Data:    "该记录不存在!",
		}
	}
	// 开始删除
	if err := model.DB.Delete(&result).Error; err != nil {
		return &util.Response{
			Code:    40000,
			Message: "failed",
			Data:    "删除失败!",
		}
	}
	return &util.Response{
		Code:    200,
		Message: "success",
		Data:    "删除成功!",
	}
}
